// 文件路径: src/main/java/com/cupk/controllers/AiController.java

package com.cupk.controllers;

import com.cupk.dtos.GenerateDescriptionRequest;
import com.cupk.services.AiService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

@RestController
@RequestMapping("/ai")
@RequiredArgsConstructor
public class AiController {

    private final AiService aiService;

    @PostMapping("/generate-description")
    @PreAuthorize("isAuthenticated()")
    public ResponseEntity<?> generateDescription(@Valid @RequestBody GenerateDescriptionRequest request) {
        String description = aiService.generateProjectDescription(request);
        return ResponseEntity.ok(Map.of("description", description));
    }
}